// 一个非常简化的useState实现
const React = (function () {
    let hooks = [];
    let currentHook = 0;
  
    return {
      useState(initialValue) {
        hooks[currentHook] = hooks[currentHook] || initialValue;
        const setStateHookIndex = currentHook; // 用于闭包内的setState
        const setState = newValue => (hooks[setStateHookIndex] = newValue);
        return [hooks[currentHook++], setState];
      },
      render(Component) {
        const Comp = Component();
        Comp.render();
        currentHook = 0; // 重置hook索引
      }
    };
  })();
  
  // 使用示例
  function MyComponent() {
    const [count, setCount] = React.useState(0);
  
    return {
      click: () => setCount(count + 1),
      render: () => console.log('render:', { count })
    };
  }
  
  // 渲染组件
  React.render(MyComponent); // render: { count: 0 }
  // 模拟用户点击事件
  MyComponent().click();
  // 重新渲染组件
  React.render(MyComponent); // render: { count: 1 }